package neuronet.common;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class NeuroNetController {

    // log4j-Logger
    private static Logger logger = Logger.getLogger(NeuroNetController.class);

    // default server ip and port
    private static int serverPort = 1504;
    private static String serverURL = "localhost";

    public NeuroNetController()
    {
	//create Server

	//	NeuroNetServer server = new NeuroNetServer(serverPort);
	NeuroNetControllerSThread s = new NeuroNetControllerSThread(serverPort);
	s.start();
	logger.info(" Corntoller has created ServerThread ...");

	//sleep for 1000 ms while server starts
	try
	{
	    Thread.currentThread().sleep(1000);
	}
	catch (InterruptedException e)
	{
	    logger.error(" Error while sleeping ... ");
	}

	for (int i = 0; i < 5; i++)
	{
	    String clientID1 = "client000" + i;
	    createClient(clientID1);
	}

    }

    private void createClient(String clientID1)
    {
	// create client 1
	//	NeuroNetClient client1 = new NeuroNetClient(serverURL, serverPort, clientName1);
	NeuroNetControllerCThread c1 = new NeuroNetControllerCThread(serverURL, serverPort, clientID1);
	c1.start();
	logger.info(" Corntoller has created client " + clientID1 + " ...");
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {
	// Set up a simple configuration that logs on the console.
	//	BasicConfigurator.configure();

	DOMConfigurator.configure("M:\\bugging\\workspace\\Neuro-Net\\log4j.xml");

	logger.info(" starting NeuroNetController.");
	new NeuroNetController();
    }

}
